-------------------------------------------------------------------------------------
-- -*- coding: utf-8 -*-
--
-- @author:   zxf
-- @email:    07291@qq.com
-- @date:     2024/5/31
-- @module:   skill
-- @describe:
-- @version:  v1.0
--

-------------------------------------------------------------------------------------

---@class skill
local skill = {}
local this = skill

local mastery_ctx = mastery_ctx
local mastery_unit = mastery_unit
local skill_unit = skill_unit
local skill_ctx = skill_ctx

---@type skill_cfg
local skill_cfg = import("game/config/skill_cfg")

-- 通过名字得到技能信息
function this.get_skill_info_by_name(skillList, skill_name)
    -- 遍历该技能列表，获取与参数一致技能名的技能信息，返回其number值
    for _, skill_info in ipairs(skillList) do
        if skill_info.name == skill_name then
            return skill_info
        end
    end
end

-- 获得技能配置
function this.get_skill_config_by_name(skillConfigs, skillName, nowLevel)
    for _, v in ipairs(skillConfigs) do
        if v.name == skillName and v.level > nowLevel then
            --xxmsg(skillName)
            --xxmsg(v.level)
            --xxmsg(nowLevel)
            return v
        end
    end
    return nil
end

-- 得到技能列表
function this.get_skill_list()
    local list = skill_unit.list()
    local skill_list = {}
    for i = 1, #list do
        local obj = list[i]
        if skill_ctx:init(obj) then
            table.insert(skill_list, {
                id = skill_ctx:id(),
                group_id = skill_ctx:group_id(),
                --cd = skill_ctx:cooling_time(),
                --mp = skill_ctx:mp(),
                is_study = skill_ctx:is_study(),
                name = skill_ctx:name(),
                level = skill_ctx:level(),
            })
        end
    end
    return skill_list
end

-- 得到熟练度列表
function this.get_mastery_list()
    local list = mastery_unit.list()
    local ret = nil
    for i = 1, #list do
        local obj = list[i]
        if mastery_ctx:init(obj) then
            if not ret then
                ret = {}
            end
            table.insert(ret, {
                obj = obj,
                id = mastery_ctx:id(),
                level = mastery_ctx:level(),
                class_id = mastery_ctx:class_id(),
                is_study = mastery_ctx:is_study()
            })
        end
    end
    return ret
end

return this
